<?php
	header('Content-type: application/json');
	header('Access-Control: allow <*>');
	include("includes/connect.php");
	$username = $_GET['username'];
    	$password = $_GET['password'];
	if ($username && $password)
	{
	    	$username = strip_tags($username);
    		$password = md5($password);

		$query = "SELECT * FROM `user_table` WHERE `username` = '$username' and `password` = '$password'";
    		$result = mysql_query($query) or die("Cannot connect to database users table");
    		$result2 = mysql_fetch_array($result);

	    	if($result2)
    		{
			$resultMSG['message']="User logged in.";
			$resultMSG['returnCode']=1;
			$resultMSG['username']= $_GET['username'];
			echo json_encode($resultMSG);
		}
	    	else
	    	{
			$resultMSG['message']="User not authenticated. Please check username and password.";
			$resultMSG['returnCode']=0;
			$resultMSG['username']= $_GET['username'];
			echo json_encode($resultMSG);
		}
	}
	else {
		$resultMSG['message']="Make sure to include both a username and password.";
		$resultMSG['returnCode']=3;
		$resultMSG['username']= $_GET['username'];
		echo json_encode($resultMSG);
	}
?>